package tech.aistar.Conteoller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tech.aistar.mapper.ApplyedMapper;
import tech.aistar.mapper.JobMapper;
import tech.aistar.model.dto.AllJobCompanyDTO;
import tech.aistar.model.dto.Code;
import tech.aistar.model.dto.Result;
import tech.aistar.model.entity.Applyed;
import tech.aistar.model.entity.Company;
import tech.aistar.model.entity.Customer;
import tech.aistar.model.entity.Job;
import tech.aistar.service.ICompanyService;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("applyed")
public class ApplyedController {
    @Autowired
    private JobMapper jobMapper;

    @Autowired
    private ICompanyService iCompanyService;

    @Autowired
    private ApplyedMapper applyedMapper;


    @Autowired
    private RedisTemplate redisTemplate;

    @ResponseBody
    @GetMapping("undo")
    public Result unDo(String deals){
        Integer dealS= Integer.valueOf(deals);
        Customer customer= (Customer) redisTemplate.opsForValue().get("customer");
        List<Applyed> applyeds=applyedMapper.getByCIdDealS(customer.getId(),dealS);
        List<Integer> ids=new ArrayList<>();
        for (int i=0;i<applyeds.size();i++){
            ids.add(applyeds.get(i).getJobId());
        }
        List<Job> jobs=jobMapper.getByIds(ids);
        List<Company> companies=iCompanyService.findAllCompany();
        AllJobCompanyDTO allJobCompanyDTO=new AllJobCompanyDTO();
        allJobCompanyDTO.setJobList(jobs);
        allJobCompanyDTO.setCompanyList(companies);
        return new Result(Code.OK,"查找成功",allJobCompanyDTO);    }
}
